package gui;
import java.awt.*;

public class UIUtil {

  public static void centerDialog(Window owner,Dialog dlg) {
    Dimension dlgSize = dlg.getPreferredSize();
    Dimension frmSize = owner.getSize();
    Point loc = owner.getLocation();
    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);

  }

  public static void centerDialog(Component owner,Dialog dlg){
    Dimension dlgSize = dlg.getPreferredSize();
    Dimension frmSize = owner.getSize();
    Point loc = owner.getLocation();
    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
  }

  public static void centerComponentOnScreen(Component comp,int ofsx,int ofsy){
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = comp.getSize();  /*Preferred*/
    if (frameSize.height > screenSize.height)
      frameSize.height = screenSize.height;
    if (frameSize.width > screenSize.width)
      frameSize.width = screenSize.width;
    comp.setLocation(((screenSize.width - frameSize.width) / 2)+ofsx, ((screenSize.height - frameSize.height) / 2)+ofsy);
  }

  public static void centerComponentOnScreen(Component comp){
    centerComponentOnScreen(comp,0,0);
  }

}
